from django.db import models
from rest_framework import serializers

from user.models import User


# Create your models here.
class Record(models.Model):
    id = models.AutoField(primary_key=True)  # 主键，自增
    name = models.CharField(max_length=100, verbose_name="垃圾名称")  # 垃圾名称
    category = models.CharField(max_length=100, verbose_name="垃圾类别")  # 垃圾类别（如可回收物、有害垃圾等）
    recycle_method = models.TextField(verbose_name="垃圾处理建议")  # 垃圾的垃圾处理建议
    image = models.CharField(max_length=255, null=True, blank=True, verbose_name="垃圾图片")  # 垃圾图片
    created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")  # 创建时间
    updated_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")  # 更新时间
    class Meta:
        db_table = 'record'


class RecordSerializer(serializers.ModelSerializer):
    class Meta:
        model = Record
        fields = '__all__'


# 系统用户角色关联类
class UserRecord(models.Model):
    id = models.AutoField(primary_key=True)
    record = models.ForeignKey(Record, on_delete=models.PROTECT)
    user = models.ForeignKey(User, on_delete=models.PROTECT)

    class Meta:
        db_table = "user_record"


class UserRecordSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserRecord
        fields = '__all__'
